package cn.uniqueinfo.dp.vo;

import cn.uniqueinfo.dp.util.MetaDataUtil;
import lombok.Data;

import java.sql.ResultSetMetaData;
import java.sql.SQLException;

/**
 * @author:朱元勋
 * @mail:395910063@qq.com
 * @date:2019-01-14 10:29:12
 * @description: 查询sql 字段元数据
 */
@Data
public class ColumnMetaDataVO {

    /** 表名 */
    private String tableName;
    /** 字段名称 */
    private String columnName;
    /** 字段类型对应的java类型 */
    private String className;
    /** sql语句中as别名 */
    private String columnLabel;
    /** 字段类型 */
    private String columnType;
    /** 业务表单标识 */
    private String formName;

    public ColumnMetaDataVO() {}

    public ColumnMetaDataVO(String formName, ResultSetMetaData rsmd, Integer column) {
        try {
            this.formName = formName;
            this.tableName = rsmd.getTableName(column);
            this.columnName = rsmd.getColumnName(column);
            this.className = rsmd.getColumnClassName(column);
            this.columnLabel = rsmd.getColumnLabel(column);
            this.columnType = MetaDataUtil.getJavaType(rsmd.getColumnTypeName(column));
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
